library(tidytuesdayR)
#This will open up in the help window
tidytuesdayR::tt_available()
Load your dataset in with the function below. The input is the date the dataset was issued. You should be able to get this from the tt_available() function.
#incoming data comes in as a list
datasets <- tidytuesdayR::tt_load("2020-08-11")
--- Compiling #TidyTuesday Information for 2020-08-11 ----
--- There are 2 files available ---
--- Starting Download ---
Downloading file 1 of 2: `avatar.csv`
Downloading file 2 of 2: `scene_description.csv`
--- Download complete ---
#show the names of the individual datasets
names(datasets)
[1] "avatar" "scene_description"
avatar <- datasets$avatar
avatar[1:5,]
scenes <- datasets$scene_description
scenes[1:5,]
Does the sentiment of each character change over the multiple seasons? That is, does a character become more positive or more negative as their character develops?
I will attempt to summarize the sentiment of each character across each episode.
Using tidytext
library(tidytext)
library(tidyverse)
avatar_words <- avatar %>%
select(id, book, book_num, chapter, chapter_num, character, character_words) %>%
filter(character != "Scene Description") %>%
unnest_tokens(word, character_words)
avatar_words[1:10,]
avatar_words %>%
count(character) %>%
arrange(desc(n)) %>%
gt::gt()
| character | n |
|---|---|
| Sokka | 18293 |
| Aang | 17821 |
| Katara | 14961 |
| Zuko | 8972 |
| Toph | 5434 |
| Iroh | 5252 |
| Azula | 3299 |
| Zhao | 1607 |
| Jet | 1604 |
| Suki | 1221 |
| Hakoda | 1065 |
| Pathik | 1030 |
| Roku | 1015 |
| Ozai | 1002 |
| Hama | 955 |
| Mai | 844 |
| Bumi | 818 |
| Long Feng | 757 |
| Warden | 722 |
| Ty Lee | 705 |
| Piandao | 671 |
| Bato | 656 |
| Mechanist | 655 |
| Yue | 559 |
| Jeong Jeong | 557 |
| Pakku | 556 |
| Kuei | 524 |
| Chong | 487 |
| Joo Dee | 471 |
| Sozin | 454 |
| Zhang leader | 447 |
| Zei | 422 |
| Teo | 374 |
| Arnook | 365 |
| Fong | 355 |
| Wu | 340 |
| Sun Warrior chief | 338 |
| Shyu | 330 |
| Gan Jin leader | 326 |
| Young Azula | 320 |
| Haru | 313 |
| Tong | 288 |
| Xin Fu | 288 |
| Ursa | 287 |
| Wan Shi Tong | 275 |
| Young Zuko | 263 |
| June | 255 |
| Canyon guide | 247 |
| Chit Sang | 245 |
| Huu | 237 |
| Tyro | 235 |
| Gyatso | 230 |
| Smellerbee | 224 |
| Guard | 212 |
| Lao | 211 |
| Oyaji | 209 |
| Chey | 208 |
| Dock | 204 |
| Herbalist | 202 |
| Actress Katara | 198 |
| Jin | 198 |
| Yu | 188 |
| Xu | 185 |
| Gan Jin tribesman | 182 |
| Li | 181 |
| Koh | 180 |
| Fisherman | 174 |
| Calm man | 173 |
| Qin | 170 |
| Meng | 168 |
| Old wanderer | 166 |
| Soldier | 164 |
| Yung | 161 |
| Actress Aang | 160 |
| Kanna | 159 |
| Tho | 157 |
| Actor Sokka | 154 |
| Song | 153 |
| King Bumi | 152 |
| Headmaster | 148 |
| Yon Rha | 146 |
| Captain | 144 |
| Due | 143 |
| Trainer | 140 |
| Pirate captain | 139 |
| The Boulder | 137 |
| Ding | 135 |
| Hahn | 134 |
| Kyoshi | 134 |
| Lee | 134 |
| Sela | 132 |
| Senlin Village leader | 132 |
| Chan | 131 |
| Fire Sage | 130 |
| Ghashiun | 127 |
| General Sung | 126 |
| Kwan | 125 |
| Ticket lady | 125 |
| Jee | 120 |
| Warden Poon | 119 |
| Male guard | 117 |
| Bully guard | 116 |
| Shinu | 116 |
| Gow | 112 |
| Oh | 111 |
| Actor Zuko | 106 |
| Fung | 106 |
| Gansu | 105 |
| General How | 105 |
| Shuzumu | 103 |
| Ying | 102 |
| Fisherman's wife | 101 |
| Avatar Roku | 98 |
| Earthbender captain | 98 |
| Fire Navy officer | 98 |
| Kenji | 94 |
| Haru's mother | 93 |
| Yangchen | 90 |
| Mung | 89 |
| Quon | 89 |
| Yugoda | 89 |
| Actress Azula | 87 |
| Great Fire Sage | 86 |
| Tashi | 83 |
| Storyteller | 82 |
| Kuruk | 81 |
| Actor Ozai | 79 |
| Pipsqueak | 79 |
| Kya | 78 |
| Lion turtle | 78 |
| Mother Superior | 78 |
| Ukano | 78 |
| Old Sweepy | 76 |
| Pao | 73 |
| Male student | 72 |
| Malu | 69 |
| Dealer | 68 |
| Female guard | 68 |
| Than | 68 |
| Music teacher | 66 |
| Actor Toph | 64 |
| Mongke | 63 |
| Man | 61 |
| Gate guard | 60 |
| Pasang | 59 |
| Azulon | 57 |
| Lo | 57 |
| Pong | 57 |
| Hide | 56 |
| Male student #2 | 55 |
| Engineer | 53 |
| Servant | 53 |
| The Duke | 53 |
| Villager | 52 |
| Shoji | 51 |
| Bujing | 50 |
| Macmu-Ling | 50 |
| Dai Li agent | 48 |
| Tycho | 48 |
| Old man | 46 |
| Lo and Li | 45 |
| Yon Rha's mother | 45 |
| Actor Iroh | 44 |
| On Ji | 44 |
| Scary prisoner | 43 |
| Sha-Mo | 43 |
| Shop owner | 43 |
| Fat | 42 |
| Momo | 42 |
| Class | 41 |
| Customer | 40 |
| Broadsword man | 39 |
| Lily | 39 |
| Cabbage merchant | 38 |
| Earth Kingdom soldier | 38 |
| Head of the Dai Li | 38 |
| University student | 38 |
| Blue dragon | 37 |
| Oracle | 37 |
| Woman | 37 |
| Poppy | 36 |
| Air Nomad boy #1 | 35 |
| Village Woman | 35 |
| Moku | 34 |
| Pet store owner | 34 |
| Appa | 33 |
| Male guard #2 | 33 |
| Ming | 33 |
| Store owner | 33 |
| Banished servant | 32 |
| Dock/Xu | 32 |
| Ham Ghao | 32 |
| Merchant #2 | 32 |
| Town authority | 32 |
| Fire Nation man | 31 |
| Ticket woman | 31 |
| Tough prisoner | 31 |
| Weapons store shopkeeper | 31 |
| Young Katara | 31 |
| Koko | 30 |
| Southern Raiders commander | 30 |
| Terra Team member | 30 |
| Fire Nation watchman #1 | 29 |
| Guard captain | 29 |
| Captured agent | 28 |
| Little boy | 28 |
| Male soldier | 28 |
| Tax collector | 28 |
| Lin Yee | 27 |
| Male student #1 | 27 |
| Merchant | 27 |
| Head of Dai Li | 26 |
| Merchant #1 | 26 |
| Ruon-Jian | 26 |
| Song's mother | 26 |
| Agent | 25 |
| Door guard | 25 |
| Guard one | 25 |
| Michi | 25 |
| Servant #1 | 25 |
| Air Nomad boy #2 | 24 |
| Red dragon | 24 |
| Villager #2 | 24 |
| Commander | 23 |
| Florist | 23 |
| Kyoshi Warrior #1 | 23 |
| Ember Island teenager #3 | 22 |
| Fire Nation soldier | 22 |
| Painter | 22 |
| Ember Island teenager #2 | 21 |
| Elder soldier | 20 |
| Li and Lo | 20 |
| Chamberlain | 19 |
| Female prisoner | 19 |
| Joo Dee replacement | 19 |
| Merchant woman | 19 |
| White Lotus member | 19 |
| Actor Jet | 18 |
| Actress Yue | 18 |
| Brainwasher | 18 |
| Fire Nation Man | 18 |
| Flyer distribution man | 18 |
| Joo Dees | 18 |
| Baboon spirit | 17 |
| Ember Island teenager #1 | 17 |
| Male Fire Nation soldier | 17 |
| Resistance fighter #1 | 17 |
| Star | 17 |
| Fire Nation Soldier | 16 |
| Gondola guard | 16 |
| Huge round angry face | 16 |
| Scout #1 | 16 |
| Second Engineer | 16 |
| Villager #3 | 16 |
| Younger guest | 16 |
| Blue Spirit | 15 |
| Lady on stage | 15 |
| Sandbender #2 | 15 |
| Sun Warrior | 15 |
| Unnamed Fire Nation boy | 15 |
| Actor Bumi | 14 |
| Crew member | 14 |
| Crowd | 14 |
| Female Fire Nation soldier | 14 |
| Guard two | 14 |
| Gyatso and Katara | 14 |
| Pirate | 14 |
| Sandbender #1 | 14 |
| Scout #2 | 14 |
| Longshot | 13 |
| Messenger | 13 |
| Old Fire Nation civilian | 13 |
| Bodyguard #2 | 12 |
| Earthbender guard | 12 |
| Guest | 12 |
| Male prisoner #1 | 12 |
| Prisoner | 12 |
| Scribe | 12 |
| Sensitive ruffian | 12 |
| Young boy | 12 |
| Firebender | 11 |
| Gondola guard #2 | 11 |
| Koala sheep | 11 |
| Lieutenant Jee | 11 |
| Little girl | 11 |
| Officer | 11 |
| Puppet Fire Lord | 11 |
| Southern Water Tribe boy | 11 |
| Tea seller | 11 |
| Waiter | 11 |
| Aang: | 10 |
| Iio | 10 |
| Qin Lee | 10 |
| Colonists | 9 |
| Farmer | 9 |
| Fire Nation Captain | 9 |
| Village girl | 9 |
| Warrior | 9 |
| Young guest | 9 |
| Fire Nation watchman #2 | 8 |
| Servant #2 | 8 |
| Villager #4 | 8 |
| Adult guest | 7 |
| Girl with umbrella | 7 |
| Gondola guard #4 | 7 |
| Man with Red Shoes | 7 |
| Mask dealer | 7 |
| Southern Water Tribe girl | 7 |
| Young Ty Lee | 7 |
| Aunt Wu | 6 |
| Big Bad Hippo | 6 |
| Bodyguard | 6 |
| Eye-patch soldier | 6 |
| Gan Jin man | 6 |
| Older guest | 6 |
| Royal messenger | 6 |
| Shop keeper | 6 |
| Spectators | 6 |
| Ta Min | 6 |
| Train conductor | 6 |
| Citizen | 5 |
| Gan Jin Leader | 5 |
| Resistance fighter #2 | 5 |
| Strange Man | 5 |
| Water Tribe warrior | 5 |
| Young Mai | 5 |
| Bogyguard #2 | 4 |
| Boy's mother | 4 |
| Female Student #1 | 4 |
| Fire Nation kids | 4 |
| Gondola guard #3 | 4 |
| How | 4 |
| Little Girl | 4 |
| Lu Ten | 4 |
| Male prisoner #2 | 4 |
| Old woman | 4 |
| Peasant girl | 4 |
| Princess Yue | 4 |
| Resistance fighter | 4 |
| Sha-Mo: | 4 |
| Tribal man | 4 |
| Village boy | 4 |
| Villagers | 4 |
| Both | 3 |
| Female student #1 | 3 |
| Firebenders | 3 |
| Guard #2 | 3 |
| Ladies | 3 |
| Poi | 3 |
| Team Avatar | 3 |
| Third girl | 3 |
| Village kids | 3 |
| Aang and Sokka | 2 |
| Girl | 2 |
| Painted Lady | 2 |
| Ping | 2 |
| Student | 2 |
| Terra Team leader | 2 |
| The Hippo | 2 |
| Villager #1 | 2 |
| Aang and Zuko | 1 |
| Audience | 1 |
| Fangirls | 1 |
| Katara and Sokka | 1 |
| Kyoshi Warrior #2 | 1 |
| Male soldier #1 | 1 |
| Man in the bar | 1 |
| Palace woman | 1 |
| Poi and Ping | 1 |
| Prisoner #2 | 1 |
| Shopkeeper | 1 |
| Together | 1 |
| Toph and Sokka | 1 |
bing <- get_sentiments("bing")
characters <- c("Aang", "Katara", "Zuko", "Toph", "Iroh", "Sokka", "Azula", "Mai", "Ty Lee")
sentiment_summary <- avatar_words %>%
inner_join(bing) %>%
count(book_num, chapter_num, chapter, character, sentiment) %>%
filter(character %in% characters) %>%
arrange(book_num, chapter_num) %>%
pivot_wider(names_from = sentiment, values_from = n) %>%
mutate(positive = tidyr::replace_na(positive, 0),
negative = tidyr::replace_na(negative, 0)) %>%
mutate(sentiment = positive - negative)
Joining, by = "word"
index_chapters <- avatar_words %>%
select(book_num, chapter_num) %>%
distinct() %>%
mutate(index = row_number())
sentiment_index <- sentiment_summary %>%
inner_join(y= index_chapters, by=c("book_num", "chapter_num"))
out_plot <- ggplot(sentiment_index) +
aes(x=index, y=sentiment, fill=character, episode=chapter) +
geom_col(show_legend = FALSE) +
facet_wrap(~character, ncol=2) +
labs(title= "Each Character's Sentiment Journey", x="Episode Number",
subtitle = "mouse over each graph for more information")
Ignoring unknown parameters: show_legend
plotly::ggplotly(out_plot)
NA
zuko <- sentiment_index %>%
filter(character=="Zuko")
out_plot <- ggplot(zuko) +
aes(x=index, y=sentiment, fill=character, episode=chapter) +
geom_col(show_legend = FALSE) +
facet_wrap(~character, ncol=2) +
labs(title= "Zuko has lots of ups and downs", x="Episode Number",
subtitle = "mouse over for more episode information")
Ignoring unknown parameters: show_legend
plotly::ggplotly(out_plot)
NA
NA